package org.filecollector.filecontroller;

import lombok.NonNull;
import org.filecollector.filecontroller.operationresults.OperationResponse;
import org.filecollector.filecontroller.basicsfilecontroller.BasicsFileControllerClass;
import org.filecollector.filecontroller.virtualcatalogue.groupname.GroupName;

/**
 * File Controller facade
 */
public interface FileController {
    /**
     * Creates file and put buffer
     * @param id identificator of file. {@code id} should match to id diapason of inner catalogues
     * @param buffer buffer that will be written to file
     * @return {@link OperationResponse} object
     * @see BasicsFileControllerClass#createBuf(Long, String)
     */
    OperationResponse createBuf(@NonNull Long id, @NonNull String buffer);

    /**
     * Creates empty file
     * @param id identificator of file. {@code id} should match to id diapason of inner catalogues
     * @return {@link OperationResponse} object
     * @see BasicsFileControllerClass#createEmpty(Long)
     */
    OperationResponse createEmpty(@NonNull Long id);

    /**
     * Creates catalogue.
     * @param namePath path to directory in {@link String} format. Directory name should match to controller name:
     *                 <p>see also: {@link GroupName GroupName}</p>
     * @return {@link OperationResponse} object
     * @see BasicsFileControllerClass#createCatalogue(String)
     */
    OperationResponse createCatalogue(@NonNull String namePath);

    /**
     * Get part of file and places it to buffer
     * @param id identificator of file. {@code id} should match to id diapason of inner catalogues
     * @param size maximal size of file
     * @return {@link OperationResponse} object with text buffer or without
     * @see BasicsFileControllerClass#readBuf(Long, int)
     */
    OperationResponse readBuf(@NonNull Long id, int size);

    /**
     * Get of all id in catalogue that parameter id
     * @param id identificator of file. {@code Id} should match to id diapason of inner catalogue.
     * @return {@link OperationResponse} object with text buffer contains id in JSON format:
     * <p>{@code ({"id":[...]})} with {@link String} elements; or without buffer</p>
     * @see BasicsFileControllerClass#readIdGroup(Long)
     */
    OperationResponse readIdGroup(@NonNull Long id);

    /**
     * Get array of group names
     * @return {@link OperationResponse} object with text buffer contains id in JSON format:
     * <p>{@code ({"groups":[...]})} with {@link String} elements; or without buffer</p>
     * @see BasicsFileControllerClass#readGroups()
     */
    OperationResponse readGroups();

    /**
     * Get all id tracking by implemented class
     * @return {@link OperationResponse} object with text buffer contains id in JSON format:
     * <p>{@code ({"id":[...]})} with {@link String} elements; or without buffer</p>
     * @see BasicsFileControllerClass#readAllIds()
     */
    OperationResponse readAllIds();

    /**
     * Get free ids of tracking catalogue that contains {@code groupId}
     * @param groupId any id in tracking catalogue
     * @return {@link OperationResponse} object with text buffer contains id in JSON format:
     * <p>{@code ({"diapason":[["String","String"][...]...]})} with {@link String} elements; or without buffer</p>
     * @see BasicsFileControllerClass#readFreeIds(Long)
     */
    OperationResponse readFreeIds(@NonNull Long groupId);

    /**
     * Put new buffer to file
     * @param id identificator of file. {@code Id} should match to id diapason of inner catalogues
     * @param buffer buffer that will be written to file
     * @return {@link OperationResponse} object
     * @see BasicsFileControllerClass#updateBuf(Long, char[])
     */
    OperationResponse updateBuf(@NonNull Long id, @NonNull char[] buffer);


    /**
     * Put new buffer to the end of file
     * @param id identificator of file. {@code Id} should match to id diapason of inner catalogues
     * @param buffer buffer that will be written to file
     * @return {@link OperationResponse} object
     * @see BasicsFileControllerClass#updateAppendBuf(Long, char[])
     */
    OperationResponse updateAppendBuf(@NonNull Long id, @NonNull char[] buffer);

    /**
     * Remove file
     * @param id identificator of file. {@code Id} should match to id diapason of inner catalogues
     * @return {@link OperationResponse} object
     * @see BasicsFileControllerClass#delete(Long)
     */
    OperationResponse delete(@NonNull Long id);

    /**
     * Removes tracking catalogue <b>without</b> removing system directory and inner files
     * @param anyId id from tracking diapason
     * @return {@link OperationResponse} object
     * @see BasicsFileControllerClass#deleteCatalogueSoft(Long)
     */
    OperationResponse deleteCatalogueSoft(@NonNull Long anyId);

    /**
     * Removes tracking catalogue <b>and</b> removes system directory and inner files
     * @param anyId id from tracking diapason
     * @return {@link OperationResponse} object
     * @see BasicsFileControllerClass#deleteCatalogueHard(Long)
     */
    OperationResponse deleteCatalogueHard(@NonNull Long anyId);
}
